package edu.mse.camel.client.log;

import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Status;

import edu.mse.camel.client.core.plugin.Activator;


public class Debug {
	
	static private File log = new File(
			Activator.getDefault().getStateLocation() 
			+ System.getProperty("file.separator") 
			+ "camel.log");
	
	static private BufferedWriter out;
	
	static public void log_info(String pluginId, String msg) {
		log_impl(Status.INFO, pluginId, msg);
	}
	
	static public void log_warning(String pluginId, String msg) {
		log_impl(Status.WARNING, pluginId, msg);
	}
	
	static public void log_error(String pluginId, String msg) {
		log_impl(Status.ERROR, pluginId, msg);
	}
		
	static private void log_impl(int level, String pluginId, String msg) {
		
		try {
			if (out == null) {
				out = new BufferedWriter(new FileWriter(log));
			}
			StringBuffer bfr = new StringBuffer();
			if(level == Status.INFO) {
				bfr.append("INFO : ");
			}
			else if(level == Status.WARNING) {
				bfr.append("WARN : ");
			}
			else if(level == Status.ERROR) {
				bfr.append("ERR  : ");
			}
			bfr.append(msg);
			out.write(bfr.toString());
			out.write(System.getProperty("line.separator"));
			out.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//Activator.getDefault().getLog().log(new Status(level, pluginId, msg));
	}
	
}
